from collections import deque
from typing import List, Union, Optional

null = None


class TreeNode:
    def __init__(self, val=0, left=None, right=None):
        self.val = val
        self.left = left
        self.right = right


def build_tree_from_level_order(arr: List[Union[int, None]]) -> Optional[TreeNode]:
    if not arr or arr[0] is None:
        return None

    # 创建根节点
    root = TreeNode(arr[0])
    queue = deque([root])  # 存储待处理节点
    i = 1  # 当前处理位置指针
    n = len(arr)

    while queue and i < n:
        node = queue.popleft()  # 取出待处理节点

        # 处理左子节点
        if i < n:
            left_val = arr[i]
            i += 1
            if left_val is not None:
                left_node = TreeNode(left_val)
                node.left = left_node
                queue.append(left_node)

        # 处理右子节点
        if i < n:
            right_val = arr[i]
            i += 1
            if right_val is not None:
                right_node = TreeNode(right_val)
                node.right = right_node
                queue.append(right_node)

    return root
